#include <iostream>
#include <cmath>
#include <cstring>
#include <queue>
#include <cstdio>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 105;
int d[maxn][maxn];
int n;
int min(int x, int y)
{
	return (x < y) ? x : y;
}
int res, ans;
void floyd()
{
	int i, j, k;
	bool flag;

	// Floyds算法求出两两之间最短距离
	for (k = 1; k <= n; k++)
	{
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (d[i][k] < inf && d[k][j] < inf && d[i][j] > d[i][k] + d[k][j])
				{
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}

	// 枚举每个点
	for (i = 1; i <= n; i++)
	{
		int MAX = -1;
		for (j = 1; j <= n; j++)
		{
			if (i == j)
				continue;
			if (d[i][j] > MAX)
			{
				MAX = d[i][j];
			}
		}
		if (MAX < ans)
		{
			ans = MAX;
			res = i;
		}
	}
	return;
}
int main()
{
	int i, j, k, t, v, w;
	// freopen("in.txt", "r", stdin);
	while (scanf("%d", &n), n)
	{
		res = -1, ans = inf;
		memset(d, inf, sizeof(d));
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &t);
			while (t--)
			{
				scanf("%d %d", &v, &w);
				d[i][v] = min(d[i][v], w);
			}
		}
		floyd();
		printf("%d %d\n", res, ans);
	}
	return 0;
}